//package com.caishi.lkx.user.api;
//
//import cn.hutool.core.collection.CollUtil;
//import cn.hutool.core.map.MapUtil;
//import cn.hutool.core.util.StrUtil;
//import cn.hutool.json.JSONObject;
//import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
//import com.caishi.lkx.common.AdminBaseApi;
//import com.caishi.lkx.user.model.GroupModel;
//import com.caishi.lkx.user.service.IGroupService;
//import com.caishi.lkx.user.service.impl.UserServiceImpl;
//import com.zzw.common.Wrappers;
//import com.zzw.common.exception.BizRuntimeException;
//import com.zzw.common.utils.TimeUtil;
//
//import com.caishi.lkx.user.model.GroupLogRuleModel;
//
////import com.caishi.lkx.user.service.IGroupLogRuleService;
//
//import io.swagger.v3.oas.annotations.tags.Tag;
//import lombok.extern.slf4j.Slf4j;
//import org.springframework.web.bind.annotation.*;
//
//import javax.annotation.Resource;
//import java.time.LocalDateTime;
//import java.util.ArrayList;
//import java.util.List;
//import java.util.stream.Collectors;
//
//
//@Tag(name = "机构日志注水规则相关接口")
//@RestController
//@RequestMapping("/user/sys/group/log/rule")
//@Slf4j
//public class GroupLogRuleApi extends AdminBaseApi<IGroupLogRuleService, GroupLogRuleModel, Long> {
//    @Resource
//    private IGroupLogRuleService groupLogRuleService;
//    @Resource
//    private IGroupService groupService;
//
//    @Resource
//    private UserServiceImpl userService;
//
//    @Override
//    public IGroupLogRuleService loadService() {
//        return groupLogRuleService;
//    }
//
//    @PostMapping("/update")
//    @Override
//    public GroupLogRuleModel add(@RequestBody GroupLogRuleModel entity) {
//        if (MapUtil.isEmpty(entity.getRule())) throw new BizRuntimeException("规则不能为空");
//        if (StrUtil.isEmpty(entity.getName())) {
//            entity.setName(userService.queryName(userContext.currentUserId() + TimeUtil.DATE_TIME_FORMATTER_SC.format(LocalDateTime.now())));
//        }
//        return super.add(entity);
//    }
//
//    @PutMapping("/update")
//    @Override
//    public GroupLogRuleModel update(@RequestBody GroupLogRuleModel entity) {
//        if (MapUtil.isEmpty(entity.getRule())) throw new BizRuntimeException("规则不能为空");
//        return super.update(entity);
//    }
//
//    @PutMapping("/change-status")
//    public void changeStatus(@RequestParam Boolean stop, @RequestParam Long id) {
//        if (stop) {
//            groupLogRuleService.stopRule(id, 5);
//        } else {
//            groupLogRuleService.continueRule(id);
//        }
//    }
//
//    @Override
//    protected LambdaQueryWrapper<GroupLogRuleModel> baseWrapper(GroupLogRuleModel model, JSONObject otherParam) {
//        List<Long> groupIds = new ArrayList<>();
//        if (StrUtil.isNotBlank(model.getGroupName())) {
//            List<GroupModel> groupModels = groupService.selectList(Wrappers.<GroupModel>lambdaQuery().select(GroupModel::getId).like(GroupModel::getName, model.getGroupName()));
//            if (CollUtil.isNotEmpty(groupModels)) {
//                groupIds = groupModels.stream().map(GroupModel::getId).collect(Collectors.toList());
//            } else {
//                groupIds.add(-1L);
//            }
//        }
//        return super.baseWrapper(model, otherParam).in(CollUtil.isNotEmpty(groupIds), GroupLogRuleModel::getGroupId, groupIds);
//    }
//
//    @Override
//    protected List<GroupLogRuleModel> listCover(List<GroupLogRuleModel> result, JSONObject otherParam) {
//        var haveGroupName = otherParam.getBool("haveGroupName", false);
//        return result.stream().peek(v -> {
//            if (haveGroupName) {
//                v.setGroupName(groupService.queryName(v.getGroupId()));
//            }
//        }).toList();
//    }
//
//
//}
